package com.newMedical.medicine.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.newMedical.common.annotation.Log;
import com.newMedical.common.core.controller.BaseController;
import com.newMedical.common.core.domain.AjaxResult;
import com.newMedical.common.enums.BusinessType;
import com.newMedical.medicine.domain.YpList;
import com.newMedical.medicine.service.IYpListService;
import com.newMedical.common.utils.poi.ExcelUtil;
import com.newMedical.common.core.page.TableDataInfo;

/**
 * 药品列表Controller
 * 
 * @author zhou
 * @date 2021-11-30
 */
@RestController
@RequestMapping("/medicine/druglist")
public class YpListController extends BaseController
{
    @Autowired
    private IYpListService ypListService;

    /**
     * 查询药品列表列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:druglist:list')")
    @GetMapping("/list")
    public TableDataInfo list(YpList ypList)
    {
        startPage();
        List<YpList> list = ypListService.selectYpListList(ypList);
        return getDataTable(list);
    }

    /**
     * 导出药品列表列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:druglist:export')")
    @Log(title = "药品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YpList ypList)
    {
        List<YpList> list = ypListService.selectYpListList(ypList);
        ExcelUtil<YpList> util = new ExcelUtil<YpList>(YpList.class);
        util.exportExcel(response, list, "药品列表数据");
    }

    /**
     * 获取药品列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:druglist:query')")
    @GetMapping(value = "/{ypId}")
    public AjaxResult getInfo(@PathVariable("ypId") Long ypId)
    {
        return AjaxResult.success(ypListService.selectYpListByYpId(ypId));
    }

    /**
     * 新增药品列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:druglist:add')")
    @Log(title = "药品列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YpList ypList)
    {
        return toAjax(ypListService.insertYpList(ypList));
    }

    /**
     * 修改药品列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:druglist:edit')")
    @Log(title = "药品列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YpList ypList)
    {
        return toAjax(ypListService.updateYpList(ypList));
    }

    /**
     * 删除药品列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:druglist:remove')")
    @Log(title = "药品列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ypIds}")
    public AjaxResult remove(@PathVariable Long[] ypIds)
    {
        return toAjax(ypListService.deleteYpListByYpIds(ypIds));
    }
}
